package com.grademaster.controller;

import com.grademaster.common.R;
import com.grademaster.dto.CoursePageDto;
import com.grademaster.dto.CourseTeacherPageDto;
import com.grademaster.entity.Courses;
import com.grademaster.service.CoursesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/courses")
@Api(tags = "课程相关接口")
@CrossOrigin(origins = {"http://localhost:8081"}, allowCredentials = "true")
public class CoursesController {

    @Autowired
    private CoursesService coursesService;


    @ApiOperation("获取分页课程信息")
    @GetMapping("/page")
    public R getCoursesPage(CoursePageDto coursePageDto){
        return coursesService.getCoursesPage(coursePageDto);
    }
    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel")
    public ResponseEntity exportExcel(CoursePageDto coursePageDto){
        return coursesService.exportExcel(coursePageDto);
    }

    @ApiOperation("获取教师相关的课程列表")
    @GetMapping("/listByTeacher")
    public R getCoursesListByTeacher(){
        return coursesService.getCoursesListByTeacher();
    }

    @ApiOperation("获取学生相关的课程列表")
    @GetMapping("/listByStudent")
    public R getCoursesListByStudent(){
        return coursesService.getCoursesListByStudent();
    }

    @ApiOperation("获取分页课程教师信息")
    @GetMapping("/getpageCourseTeacher")
    public R getpageCourseTeacher(CourseTeacherPageDto courseTeacherPageDto){
        return coursesService.getpageCourseTeacher(courseTeacherPageDto);
    }
    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel2")
    public ResponseEntity exportExcel2(CourseTeacherPageDto courseTeacherPageDto){
        return coursesService.exportExcel2(courseTeacherPageDto);
    }
    @ApiOperation("生成成绩信息")
    @GetMapping("/generateScore")
    public R generateScore(CourseTeacherPageDto courseTeacherPageDto){
        return coursesService.generateScore(courseTeacherPageDto);
    }

    @ApiOperation("添加或修改课程")
    @PostMapping("/addOrEditCourse")
    public R addOrEditCourse(@RequestBody Courses courses) {
        return coursesService.addOrEditCourse(courses);
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/deleteCourse/{courseId}")
    public R deleteCourse(@PathVariable("courseId") String courseId) {
        return coursesService.deleteCourse(courseId);
    }



}
